﻿using EasyNet.Componets.Core.Http;
using EasyNet.Componets.Core.Inject;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyNet.Componets.Core.Utils
{
    public class HttpContextUtil
    {
        private static IHttpContext _instance;

        public static IHttpContext Instance
        {
            get
            {
                if (_instance != null)
                {
                    return _instance;
                }
                _instance = IoC.Resolve<IHttpContext>();

                return _instance;
            }
        }


        /// <summary>
        /// 设置实例
        /// </summary>
        /// <param name="instance"></param>
        public static void SetInstance(IHttpContext instance)
        {
            _instance = instance;
        }


        public static string GetRequestContent(object request)
        {
            return Instance.GetRequestContent(request);

        }

        public static RequestInfo GetRequestInfo(object request)
        {
            return Instance.GetRequestInfo(request);
        }

        public static string GetResponseContent(object response)
        {
            return Instance.GetResponseContent(response);
        }

        public static ResponseInfo GetResponseInfo(object response)
        {
            return Instance.GetResponseInfo(response);
        }

        public static string GetClientIp(object request)
        {
            return Instance.GetClientIp(request);
        }

        public static void SetRequestId(object request, string requestId)
        {
            Instance.SetRequestId(request, requestId);
        }

        public static string GetRequestId(object request)
        {
            return Instance.GetRequestId(request);
        }

        public static RequestAuthenticationHeaderValue GetHeaderAuthorization(object request)
        {
            return Instance.GetHeaderAuthorization(request);
        }
    }
}
